package com.topView2;

/**
 * @Author: huangzhigao
 * @Date: 2023/2/11 16:34
 */
public class leecode5 {
    public String longestPalindrome(String s) {
        if (s.length() == 0) {
            return "";
        }
        String res = "";
        for (int i = 0; i < s.length(); i++) {
            String res1 = findPalindrome(s, i, i + 1);
            String res2 = findPalindrome(s, i, i);
            res = res1.length() > res.length() ? res1 : res;
            res = res2.length() > res.length() ? res2 : res;
        }
        return res;

    }


    public String findPalindrome(String s, int left, int right) {
        while (left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right)) {
            left--;
            right++;
        }
        return s.substring(left + 1, right);
    }

}
